/**
 * Created by xiao_XX on 2017/9/7.
 */
import React from 'react';
import { Link } from 'dva/router';
import { connect } from 'dva';
import PropTypes from 'prop-types';
import styles from './SelectAssembly.less';
import {Select} from 'antd';
const Option = Select.Option;


/**
 *
 * @param selectData  传进来需要选择的数据  [{
 *                                  value:value值,
 *                                  text:显示值
 *                                    }]
 * @param size    select的尺寸:large small default
 * @param type   父组件的namespace
 * @param selectroute        父组件中的方法用来存储 选择的value值
 * @param dispatch
 * @returns {XML}
 * @constructor
 */
const SmartSelect = ({selectData,size,type,selectroute,dispatch,selectValue}) => {

  function handleChange(value) {
    dispatch({
      type: type + selectroute,
      selectValue:value
    })
  }


  var selectContent = [];
  if (selectData){
    for (var i = 0 ; i < selectData.length; i++){
      var item = selectData[i];
      selectContent.push(
        <Option
          value={item.value}
          key  = {i}
        >
          {item.text}
        </Option>
      )
    }
  }


  return (
    <div className={styles.option_width}>
      <Select defaultValue={selectValue}  onChange={handleChange} size={size} >
        {selectContent}
      </Select>
    </div>
  )

};
export default connect(({}) => ({}))(SmartSelect);
